﻿<%@ Page Language="C#"  %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script src="../../Scripts/jquery-1.7.1.min.js" type="text/javascript"></script> 
    <link href="../../Styles/jquery.validate.css" rel="stylesheet" type="text/css" /> 
    <script src="../../Scripts/jquery.validate.js" type="text/javascript"></script> 
     <script src="../../Scripts/jquery.validator.messages.js" type="text/javascript"></script>     
    <script type="text/javascript" src="../../Scripts/jquery.query.js"></script>
    <script src="../js/blockUI.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server"   method="post" action="../AjaxHandler/UserRegistryEditHandler.ashx?action=Edit">
    <div>
        <table>
           
            <tr>
                <td>
                    用户名
                </td>
                <td>
                    <input type="text" id="name" name="name" />
                </td>
            </tr>
            <tr>
                <td>
                   邮箱
                </td>
                <td>
                     <input type="text" id="email" name="email" />
                </td>
            </tr>
            <tr>
                <td>
                    密码：
                </td>
                <td>
                    <input type="password" id="password" name="password"  maxlength="20"/>
                </td>
            </tr>
            <tr>
                <td>
                    确认密码：
                </td>
                <td>
                    <input type="password" name="confirm_password"  id="confirm_password"/>
                </td>
            </tr>
           <tr>
                <td>
                    备注
                </td>
                <td>
                    <textarea id="remark" rows="5" cols="20" name="remark" ></textarea>
                </td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <input type="submit" id="btn_Save" value="保 存" /><input type="button" id="btn_Back" value="返 回"  onclick="javascript:history.back();" />
                </td>
            </tr>
        </table>
    </div>
    <input id="hidCode" name="hidCode" type="hidden" value="-1" />
    </form>
     <script type="text/javascript">
         $(document).ready(function () {
             var code = $.query.get("code");
             $("#hidCode").val(code);

             var BindData = function () {
                 if (code != "-1") { 
                  $.blockUI({ message: "<h2>数据加载中.......</h2>", css: { width: "300px", height: "50px"} });
                     $.post("../AjaxHandler/UserRegistryEditHandler.ashx", { action: "Get", hidCode: code }, function (data) {
                         $("#name").val(data.UserName);
                         $("#email").val(data.Email);
                         $("#remark").val(data.Remark);
                         $("#password").val(data.PassWord);
                         $("#confirm_password").val(data.PassWord); 
                         $.unblockUI();
                     });
                 }
                
             }
             BindData();

             $("#form1").validate({
                 rules: {
                     name: {
                         required: true,
                         remote: {
                             type: "POST",
                             url: "../AjaxHandler/CheckUserRegistryName.ashx",
                             data: { name: function () { return $("#name").val(); }, id: code }
                         }
                     },
                     email: {
                         required: true,
                         email: true,
                         remote: {
                             type: "POST",
                             url: "../AjaxHandler/CheckUserRegistryEmail.ashx",
                             data: { email: function () { return $("#email").val(); }, id: code }
                         }
                     },
                     password: {
                         required: true,
                         minlength: 5
                     },
                     confirm_password: {
                         required: true,
                         minlength: 5,
                         equalTo: "#password"
                     }
                 },
                 messages:
                    {
                        name: { required: "请输入名称", remote: "该名称已存在！" },
                        email: { required: "请输入邮箱", email: "邮箱格式不正确", remote: "该邮箱已注册" },
                        password: {
                            required: "请输入密码",
                            minlength: jQuery.format("密码不能小于{0}个字符!")
                        },
                        confirm_password: {
                            required: "请输入确认密码",
                            minlength: "确认密码不能小于5个字符",
                            equalTo: "两次输入密码不一致"
                        }
                    }
             });

         });
    </script>
</body>
</html>
